﻿function getQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) return unescape(r[2]); return null;
}

//html代码转异
function htmlDecode(str) {
    str = str.replace(/&amp;/gi, "&");
    str = str.replace(/&nbsp;/gi, " ");
    str = str.replace(/&quot;/gi, "\"");
    str = str.replace(/&#39;/g, "'");
    str = str.replace(/&lt;/gi, "<");
    str = str.replace(/&gt;/gi, ">");
    //     str = str.replace(/<br[^>]*>(?:(rn)|r|n)?/gi, "n");
    return str;
}

function ajaxDone(data, isHide) {
    var smodel;
    var flag = true;
    try {
        var jsonData = typeof (data) == "string" ? $.parseJSON(htmlDecode(data)) : data;
        switch (jsonData.statusCode.toString()) {
            case "301":
                flag = false;
                //msginfo(jsonData.message);
                LoginDialog();
                break;
            case "300":
                flag = false;
                if (!isHide) YDUI.dialog.toast(jsonData.message, 'error', 1000);;
                break;
            default:
                flag = true;
                break;
        }
    } catch (e) {

    }
    return smodel = $.parseJSON('{"flag":' + flag + ',"msg":"' + jsonData.message + '"}');
    return flag;
}

//验证是否为空
function isEmptyValue(value) {
    if (value == undefined || value == "") {
        return true;
    }
    return false;
}



//申请装修，提交订单
function submitOrder() {
    var $insName = $("#insName").val();
    var $insPhone = $("#insPhone").val();
    var $J_Address = $("#J_Address").val();
    var $insAddress = $("#insAddress").val();
    var $insHouseType1 = $("#insHouseType1").find("option:selected").text();
    var $insHouseType2 = $("#insHouseType2").find("option:selected").text();
    var $insHouseType3 = $("#insHouseType3").find("option:selected").text();
    var $insMJ = $("#insMJ").val();
    var $insZXType = $("#insZXType").find("option:selected").text();
    var $insRemark = $("#insRemark").val();

    if (isEmptyValue($insName)) {
        YDUI.dialog.toast('名称错误', 'error', 1000);
        return;
    }
    if (isEmptyValue($insPhone)) {
        YDUI.dialog.toast('手机号错误', 'error', 1000);
        return;
    }
    if (isEmptyValue($J_Address)) {
        YDUI.dialog.toast('房屋地址错误', 'error', 1000);
        return;
    }
    if (isEmptyValue($insAddress)) {
        YDUI.dialog.toast('房屋详细地址错误', 'error', 1000);
        return;
    }
    if (isEmptyValue($insHouseType1)) {
        YDUI.dialog.toast('户型室错误', 'error', 1000);
        return;
    }
    if (isEmptyValue($insHouseType2)) {
        YDUI.dialog.toast('户型厅错误', 'error', 1000);
        return;
    }
    if (isEmptyValue($insHouseType3)) {
        YDUI.dialog.toast('户型卫错误', 'error', 1000);
        return;
    }
    if (isEmptyValue($insMJ)) {
        YDUI.dialog.toast('房屋面积错误', 'error', 1000);
        return;
    }
    if (isEmptyValue($insZXType)) {
        YDUI.dialog.toast('房屋装修风格错误', 'error', 1000);
        return;
    }

    $.post("/Renovation/Create", {
        "insName": $insName, "insPhone": $insPhone, "J_Address": $J_Address, "insAddress": $insAddress,
        "insHouseType1": $insHouseType1, "insHouseType2": $insHouseType2, "insHouseType3": $insHouseType3,
        "insMJ": $insMJ, "insZXType": $insZXType, "insRemark": $insRemark
    }, function (d) {
        var data = $.parseJSON(htmlDecode(d));
        if (data.statusCode == 200) {
            YDUI.dialog.toast(data.message, 'success', 1000);
            window.history.back();
        } else {
            YDUI.dialog.toast(data.message, 'error', 1000);
            return;
        }
    });
}

///实名认证--完善个人信息
function submitInitUser() {
    var insName = $("#insName").val();
    var insIdCard = $("#insIdCard").val();
    var insUserPhone = $("#insUserPhone").val();
    var J_Address = $("#J_Address").val();

    if (isEmptyValue(insName)) {
        YDUI.dialog.toast('名称错误', 'error', 1000);
        return;
    }
    if (isEmptyValue(insIdCard)) {
        YDUI.dialog.toast('身份证错误', 'error', 1000);
        return;
    }
    if (isEmptyValue(insUserPhone)) {
        YDUI.dialog.toast('手机号错误', 'error', 1000);
        return;
    }
    if (isEmptyValue(J_Address)) {
        YDUI.dialog.toast('所属区域错误', 'error', 1000);
        return;
    }
    $.post("/Me/initUserInfo", {
        "txtName": insName, "txtIdCard": insIdCard, "txtUserPhone": insUserPhone, "ssx": J_Address
    }, function (d) {
        var data = $.parseJSON(htmlDecode(d));
        if (data.statusCode == 200) {
            YDUI.dialog.toast(data.message, 'success', 1000);
            window.history.back();
        } else {
            YDUI.dialog.toast(data.message, 'error', 1000);
            return;
        }
    });
}


//添加银行卡信息
function insAddBank() {
    var insCardNo = $("#insCardNo").val();
    var insBankName = $("#insBankName").val();
    var insBankAddress = $("#insBankAddress").val();
    var insUserCardNo = $("#insUserCardNo").val();
    var insUserPhone = $("#insUserPhone").val();
    var insUserName = $("#insUserName").val();
    if (isEmptyValue(insCardNo) || isEmptyValue(insBankName) || isEmptyValue(insBankAddress) || isEmptyValue(insUserCardNo) || isEmptyValue(insUserPhone) || isEmptyValue(insUserName)) {
        YDUI.dialog.toast('银行卡信息不得为空', 'error', 1000);
        return;
    }
    $.post("/BankManager/bankAdd", {
        "txtBankNo": insCardNo, "txtBankName": insBankName, "txtBankAddress": insBankAddress, "txtBankUserCardNo": insUserCardNo,
        "txtBankUserPhone": insUserPhone, "txtBankUserName": insUserName
    }, function (d) {
        var data = $.parseJSON(htmlDecode(d));
        if (data.statusCode == 200) {
            YDUI.dialog.toast(data.message, 'success', 1000);
            window.history.back();
        } else {
            YDUI.dialog.toast(data.message, 'error', 1000);
            return;
        }
    });
}




///计算分润
//function initFX() {
//    $.post("/Wallet/initReturnedList", {}, function (d) {
//        if (d==1) {
//            location.reload();
//        }
//    });
//}





